//判断时候在Iframe框架内,在则刷新父页面
if (self != top) {
    top.location.href = window.location.href;
    top.location.reload(true);
    if (!!(window.attachEvent && !window.opera)) {
        document.execCommand("stop");
    } else {
        window.stop();
    }
}
var app=new Vue({
    el: '#app',
    data:{
       user: {"msg":"","username":"","password":""}
    },
    methods:{
        /*
         * 登录
         */
      login: function(){
          var _this=this;
          if(!this.user.username){
              this.user.msg="用户名不能为空!";
              return false;
          }
          if(!this.user.password){
              this.user.msg="密码不能为空!";
              return false;
          }
/*          if(!this.user.captcha){
              this.user.msg="验证码不能为空!";
              return false;
          }*/
          //登录
          jsmile.http.sendJson({
              url:jsmile.url+"/sso/login",
              data:{"userType":"1","userName":_this.user.username,"password":jsmile.hash.encrypt(_this.user.password),"loginType":"username"/*,"captcha":_this.user.captcha*/}
          }).done(function(res){
              jsmile.token=res.resData.value;
              sessionStorage.setItem("token","bearer "+res.resData.value);
              window.location.href ="index.html";
          }).fail(function(res){
              _this.user.msg=res.resMsg?res.resMsg:"用户登录失败！";
          });
      }
    }
});
$(function() {
    document.onkeydown = function(e) {
        var ev = document.all ? window.event : e;
        if (ev.keyCode == 13) {//回车登录
          app.login();
        }
    }
    $(".prompt").hide();

    // 验证码
    $("#img_captcha").click(function() {
        var $this = $(this);
        var url = $this.attr("src") +"?t="+ new Date().getTime();
        $this.attr("src", url);
    });
});

